#pragma once

#ifndef __TIMER_H__
#define __TIMER_H__

#include <windows.h>

inline unsigned __int64 get_cycles()
{
	_asm
	{
		_emit 0x0f
		_emit 0x31
	}
}

inline unsigned __int64 get_cpu_clock_freq()
{
	LARGE_INTEGER before, after;
	unsigned __int64 before_c, after_c;

	::QueryPerformanceCounter(&before);
	before_c = get_cycles();
	::Sleep(100);
	after_c = get_cycles();
	::QueryPerformanceCounter(&after);

	unsigned __int64 d_count = after.QuadPart - before.QuadPart;
	unsigned __int64 d_cycles = after_c - before_c + 2000;

	LARGE_INTEGER frequency;
	::QueryPerformanceFrequency(&frequency);

	return d_cycles * (unsigned __int64)frequency.QuadPart / d_count;
}


class Timer
{
public:
	Timer();
	void reset();
	unsigned long get_elapse_milliseconds() const;
	float get_elapse_seconds() const;
	

private:
	LARGE_INTEGER m_start_count;
	static unsigned long m_freq;
	static float m_freq_f;
};

#endif // __TIMER_H__
